<?php
namespace app\home\controller;
use think\View;
use think\Db;
use think\Controller;
use app\home\model\User;

class Register extends Controller{

  public function index(){
    $view = new View();
    return $view->fetch('index');

  }

  //用户注册
  public function regist(){
    //实例化User
    /*$user = new User;
    //接收前端表单提交的数据
    $user->username = input('post.username');
    $user->user_number = input('post.user_number');
    $user->password = input('post.password');
    */
    $data['username'] = input('post.username');
    $data['user_number'] = input('post.user_number');
    $data['password'] = input('post.password');
    $link=Db::name('user')->insert($data);
    var_dump($data);
  
    $result = $this->validate(
      [
        'name' => $user->user_name,
        'email' => $user->user_email,
        'sex' => $user->user_sex,
        'tel' => $user->user_tel,
        'address' => $user->user_address,
        'birth' => $user->user_birth,
        'password' => $user->user_passwd,
      ],
      [
        'name' => 'require|max:10',
        'email' => 'email',
        'sex' => 'number|between:0,1',
        'tel' => 'require',
        'address' => 'require',
        'birth' => 'require',
        'password' => 'require',
      ]);
    // 写入数据库
    if ($link) {
      return $this->success('注册成功');
      exit();
    } else {
      return $this->error('注册失败');
      exit();
    }


  }
}
